import Vue from "vue";
import Vuex from 'vuex'
import { getInfo } from "../api/user";
import { getToken } from "../uilts/token";

Vue.use(Vuex)


const store = new Vuex.Store({
  state:{
    n:{}
  },
  mutations:{
    SET_N(state,value){
      state.n = value
    },
    REST_N(state){
      state.n = {}
    }
  },
  actions:{
    // 通过token 获取用户信息
    getUserInfo(ctx){
      return new Promise(async resolve => {
        const res = await getInfo(getToken())
        console.log(res.data.data)
        ctx.commit('SET_N',res.data.data)
        resolve()
      })
    },
    logout(ctx){
      return new Promise(resolve => {
        ctx.commit('REST_N')
        resolve()
      })
    }
  }
})


export default store
